package com.itheima.app.controller;

import com.itheima.app.manager.UserLikeManager;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.UserLikeCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@RestController
public class UserLikeController {

    @Autowired
    private UserLikeManager userLikeManager;

    /**
     * 喜欢
     * @return
     * @throws IOException
     */
    @GetMapping("/tanhua/{likeUserId}/love")
    public Map likeUser(
            @PathVariable Long likeUserId
    ) throws IOException {
        userLikeManager.likeUser( likeUserId );
        return null;
    }


    /**
     * 互相喜欢，喜欢，粉丝 - 统计
     * @return
     * @throws IOException
     */
    @GetMapping("/users/counts")
    public UserLikeCountVo findCounts(
    ) throws IOException {

        return  userLikeManager.findCounts(  );
    }



    //查询 互相喜欢，喜欢，粉丝 访客 数据
    //1 互相关注
    //2 我关注
    //3 粉丝
    //4 谁看过我
    @GetMapping("/users/friends/{type}")
    public PageBeanVo findUserInfoByType(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @PathVariable String type
    ){

        return userLikeManager.findUserInfoByType(page , pageSize , type);
    }

    //粉丝 - 喜欢
    @PostMapping("/users/fans/{userId}")
    public void saveFanLike(@PathVariable("userId") Long userId) {
        userLikeManager.saveFanLike(userId);
    }
    //喜欢 - 取消
    @DeleteMapping("/users/like/{userId}")
    public void deleteLike(@PathVariable("userId") Long userId) {
        userLikeManager.deleteLike(userId);
    }
}
